DegToUnrRot = 182.0444;

fn formattedString inputString =
(
	temp = formattedPrint inputString format:"#.3f"
	return temp
)
fn printActor id meshName meshLocation meshRotation=
(       
		zRotation = meshRotation.Z + 90
        xRotation = meshRotation.X
        yRotation = meshRotation.Y
        

        zRotation = ((zRotation * DegToUnrRot) as integer)
        yRotation = ((yRotation * DegToUnrRot) as integer)
        xRotation = ((xRotation * DegToUnrRot) as integer)
        
        xLocation = meshLocation.X 
        yLocation = -meshLocation.Y
        zLocation = 15 + meshLocation.Z
format "\t\tBegin Actor Class=StaticMeshActor Name=StaticMeshActor_% Archetype=StaticMeshActor'Engine.Default__StaticMeshActor'\n" id to: outputFile
format "\t\tBegin Object Class=StaticMeshComponent Name=StaticMeshComponent0 ObjName=StaticMeshComponent_0 Archetype=StaticMeshComponent'Engine.Default__StaticMeshActor:StaticMeshComponent0'\n" to: outputFile
format "\t\t\tStaticMesh=StaticMesh'%.%'\n" meshPack meshName to: outputFile
format "\t\t\tVertexPositionVersionNumber=2\n" to: outputFile
format "\t\t\tReplacementPrimitive=None\n" to: outputFile
format "\t\t\tbAllowApproximateOcclusion=True\n" to: outputFile
format "\t\t\tbForceDirectLightMap=True\n" to: outputFile
format "\t\t\tbUsePrecomputedShadows=True\n" to: outputFile
format "\t\t\tLightingChannels=(bInitialized=True,Static=True)\n" to: outputFile
format "\t\t\tName="StaticMeshComponent_0"\n" to: outputFile
format "\t\t\tObjectArchetype=StaticMeshComponent'Engine.Default__StaticMeshActor:StaticMeshComponent0'\n" to: outputFile
format "\t\tEnd Object\n" to: outputFile
format "\t\tStaticMeshComponent=StaticMeshComponent'StaticMeshComponent_0'\n" to: outputFile
format "\t\tComponents(0)=StaticMeshComponent'StaticMeshComponent_0'\n" to: outputFile
format "\t\tLocation=(X=%,Y=%,Z=%)\n"  (formattedString -yLocation) (formattedString xLocation) (formattedString zLocation) to: outputFile --swap x and y axis
format "\t\tRotation=(Pitch=%,Yaw=%,Roll=%)\n" yRotation zRotation -xRotation to: outputFile--swap pitch and roll, negate roll
format "\t\tCreationTime=#.3f\n" (62.354931 + id) to: outputFile
format "\t\tTag="StaticMeshActor"\n" to: outputFile
format "\t\tCollisionComponent=StaticMeshComponent'StaticMeshComponent_0'\n" to: outputFile
format "\t\tObjectArchetype=StaticMeshActor'Engine.Default__StaticMeshActor'\n" to: outputFile
format "\t\tEnd Actor\n" to: outputFile
)

meshPack = "Pinball"

outputFile = createFile "C:\\UDK\\UDK-2011-06\\UDKGame\\Content\\SIMBAC\\pinball.T3D"
objList = getCurrentSelection()
format "Begin Map\n" to: outputFile
format "\tBegin Level\n" to: outputFile

for s in selection do  
(  
 oldname = filterString s.name " "  
 temp = oldname[1]  
 for i = 2 to oldname.count do  
 (  
  temp = temp + oldname[i]  
 )  
 s.name = temp  
)  

for p=1 to objList.count do
(
        printActor p objList[p].name objList[p].Position ((objList[p].rotation as eulerAngles))
)
        
format "\tEnd Map\n" to: outputFile
format "End Level\n" to: outputFile
close outputFile

